
<? /*
	function loadChungLoaiTop($id){
		global $db,$prefix;
		$CatID = 0;
		if($id == 0){
			$sql = "SELECT * FROM ".$prefix."loaisanpham WHERE c_hienthi = 1 AND c_id_cha != 0 ORDER BY c_id DESC LIMIT 1";
			$rs = $db->query($sql);
			$row = $db->fetch_array($rs);
			$CatID = $row[c_id];
		}else if($id == 1){
			$sql = "SELECT * FROM ".$prefix."loairaovat WHERE rvc_hienthi = 1 AND rvc_id_cha != 0 ORDER BY rvc_id DESC LIMIT 1";
			$rs = $db->query($sql);
			$row = $db->fetch_array($rs);
			$CatID = $row[rvc_id];
		}else{
			$sql = "SELECT * FROM ".$prefix."loaituyendung WHERE ltd_hienthi = 1 AND ltd_id_cha != 0 ORDER BY ltd_id DESC LIMIT 1";
			$rs = $db->query($sql);
			$row = $db->fetch_array($rs);
			$CatID = $row[ltd_id];
		}
		return $CatID;
	}

	if(isset($_GET['KCL'])){
		$KCL = intval($_GET['KCL']);
	}else{
		$KCL = 0;
	}
	
	if(isset($_GET['CL'])){
		$CL = intval($_GET['CL']);
	}else{
		$CL = loadChungLoaiTop($KCL);
	}
	$sql = "SELECT * FROM ".$prefix."quangcao WHERE qc_hienthi = 1";
 
	if(isset($_GET['HT'])){
		$HT = intval($_GET['HT']);
		if($HT == 1){
			$sql .= "qc_hienthi = 1";
		}else if($VT == 2){
			$sql .= "qc_hienthi = 0";
		}
	} 
	
	if(isset($_GET['VT'])){
		$VT = intval($_GET['VT']);
		if($VT == 1){
			$sql .= " AND qc_vitri = 0";
		}else if($VT == 2){
			$sql .= " AND qc_vitri = 1";
		}
	}
	*/
	
	########################
		$sql = "SELECT * FROM ".$prefix."quangcao WHERE qc_hienthi = 1";
	echo $sql;
		if(isset($_GET['method']))
		{
			$method = $_GET['method'];
			if($method=="del"){
				$sListId="";
				if(isset($_POST["chon"]))$sListId=$_POST["chon"];
				$query="delete from ".$prefix."quangcao where qc_id in('".str_replace(",","','",$sListId)."')";
				mysql_query($query);
				Redirect("Bạn đã xoá thành công","?mod=adv&HT=$HT");
			}
			else if($method=="move"){
				$IdList=$_GET["id"];
				$move=$_GET["move"];
				$query = "UPDATE ".$prefix."quangcao
							SET qc_thutu = qc_thutu+$move
							WHERE qc_id = $IdList";
							
							
				mysql_query($query);
				//Redirect("","?mod=adv&KCL=$KCL&CL=$CL&HT=$HT&VT=$VT");
			}else if($method=="act"){
				$IdList=$_GET["id"];
				$act=$_GET["act"];
				if($act==1) $iact=0;else $iact=1;
				$query="update ".$prefix."quangcao set qc_hienthi=$iact where qc_id=$IdList";
				mysql_query($query);
				Redirect("","?mod=adv&HT=$HT");		
			}else if($method=="delete"){
				$IdList=$_GET["id"];
				$query="delete from ".$prefix."quangcao where qc_id=$IdList";
				mysql_query($query);
				Redirect("Đã xóa thành công","?mod=adv&HT=$HT");		
			}
		}
	
	
	#############################################
	
	
	
	#Paging
	$pp=10; 
	$parr=array();
	$parr=paging($sql,$pp);
	$page=$parr[0];
	$limitvalue=$parr[1];
	$numofpages=$parr[2];
	$sql.=" ORDER BY qc_thutu ASC";
	$sql.=" LIMIT $limitvalue, $pp";
	echo $sql;
	$rss = mysql_query($sql) or die('Not query');
	$i=0;
	$isexits=false;
	
	if(mysql_num_rows($rss)) $isexits=true;
?>
<div class="newsList-path"></div>
	<div style="margin-bottom:5px; font-size:14px;">
	 Có <?=$db->num_rows($rss)?> quảng cáo được tìm thấy 
	 <br /><br />
	<a href="?mod=adv.add"><img src="images/add.png" border="0" alt="Thêm mới"/></a>&nbsp;<a href="?mod=adv"><img src="images/list.png" border="0" alt="Danh sách"/></a>
</div>
<script language="javascript"> /*
	function funKieuChungLoai(KCL){ 
		window.location = '?mod=adv&KCL=' + KCL;
	}
	function funChungLoai(KCL,CL){
		window.location = '?mod=adv&KCL=' + KCL + '&CL=' + CL;
	}
	function funHienThi(KCL,CL,HT){
		window.location = '?mod=adv&KCL=' + KCL + '&CL=' + CL  + '&HT=' + HT;
	}
	function funViTri(KCL,CL,VT){
		window.location = '?mod=adv&KCL=' + KCL + '&CL=' + CL  + '&VT=' + VT;
	} */
</script>
<div align="left" class="newsList-search-up"> <!--
  <table width="399" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="174">Kiểu chủng loại : </td>
      <td width="225">
	  <select name="KieuChungLoai" id="KieuChungLoai" onchange="funKieuChungLoai(this.value);">
	  	<option value="0" <? if($KCL == 0){?> selected="selected" <? } ?>>Sản phẩm</option>
		<option value="1" <? if($KCL == 1){?> selected="selected" <? } ?>>Rao vặt</option>
		<option value="2" <? if($KCL == 2){?> selected="selected" <? } ?>>Tuyển dụng</option>
      </select>
      </td>
    </tr>
    <tr>
      <td>Chủng loại </td>
      <td><select name="ChungLoai" id="ChungLoai" onchange="funChungLoai('<?=$KCL?>',this.value)">
	  	<?
			if($KCL == 0){
				$rs = $db->query("SELECT * FROM ".$prefix."loaisanpham WHERE c_hienthi = 1 AND c_id_cha = 0 ORDER BY c_thutu ASC");
			}else if($KCL == 1){
				$rs = $db->query("SELECT * FROM ".$prefix."loairaovat WHERE rvc_hienthi = 1 AND rvc_id_cha = 0 ORDER BY rvc_thutu ASC");
			}else{
				$rs = $db->query("SELECT * FROM ".$prefix."loaituyendung WHERE ltd_hienthi = 1 AND ltd_id_cha = 0 ORDER BY ltd_thutu ASC");
			}
					while($row = $db->fetch_array($rs)){
					if($KCL == 0){
						$c_ten = $myString->unQuote(stripslashes($row[c_ten]));
						$c_id = $row[c_id];
					}else if($KCL == 1){
						$c_ten = $myString->unQuote(stripslashes($row[rvc_ten]));
						$c_id = $row[rvc_id];
					}else{
						$c_ten = $myString->unQuote(stripslashes($row[ltd_ten]));
						$c_id = $row[ltd_id];
					}
	?>	
                    <optgroup label="<?=$c_ten?>">
	<?
					if($KCL == 0){
						$rs2 = $db->query("SELECT * FROM ".$prefix."loaisanpham WHERE c_hienthi = 1 AND c_id_cha = '".$c_id."' ORDER BY c_id DESC");
					}else if($KCL == 1){
						$rs2 = $db->query("SELECT * FROM ".$prefix."loairaovat WHERE rvc_hienthi = 1 AND rvc_id_cha = '".$c_id."' ORDER BY rvc_id DESC");
					}else{
						$rs2 = $db->query("SELECT * FROM ".$prefix."loaituyendung WHERE ltd_hienthi = 1 AND ltd_id_cha = '".$c_id."' ORDER BY ltd_id DESC");
					}
						while($row2 = $db->fetch_array($rs2)){
						if($KCL == 0){
							$c_ten2 = $myString->unQuote(stripslashes($row2[c_ten]));
							$c_id2 = $row2[c_id];
						}else if($KCL == 1){
							$c_ten2 = $myString->unQuote(stripslashes($row2[rvc_ten]));
							$c_id2 = $row2[rvc_id];
						}else{
							$c_ten2 = $myString->unQuote(stripslashes($row2[ltd_ten]));
							$c_id2 = $row2[ltd_id];
						}
	?>
				<option value="<?=$c_id2?>" <? if($CL == $c_id2){ ?> selected="selected" <? } ?>><?=$c_ten2?></option>
			<? } ?>
					</optgroup>
				<? } ?>
      </select></td>
    </tr>
	 <tr>
      <td>Vị Trí </td>
      <td><select name="ViTri" id="ViTri" onchange="funViTri('<?=$KCL?>','<?=$CL?>',this.value);">
	  	<option value="0" <? if($VT == 0){ ?> selected="selected" <? } ?>> -- Tất cả -- </option>
        <option value="1" <? if($VT == 1){ ?> selected="selected" <? } ?>>Bên trái</option>
		<option value="2" <? if($VT == 2){ ?> selected="selected" <? } ?>>Bên dưới</option>
      </select></td>
  </tr>
    <tr>
      <td>Hiển thị </td>
      <td><select name="HienThi" id="HienThi" onchange="funHienThi('<?=$KCL?>','<?=$CL?>',this.value);">
	  	<option value="0" <? if($HT == 0){ ?> selected="selected" <? } ?>> -- Tất cả -- </option>
        <option value="1" <? if($HT == 1){ ?> selected="selected" <? } ?>>Hiển thị</option>
		<option value="2" <? if($HT == 2){ ?> selected="selected" <? } ?>>Không hiển thị</option>
      </select></td>
    </tr>
  </table>-->
</div>
	<form name="frmListSp" method="post" action="?mod=adv&method=del&HT=<?=$HT?>" onSubmit="return checkInput(this,'Bạn hãy chọn ít nhất một giá trị','Bạn chắc chắn muốn xoá không');">
	<input type="hidden" name="chon" />
	<table width="100%" border="1" bordercolor="#B2DAEE" cellpadding="4">
		<tr class="newsList-content-head">
		<td width="3%" class="newsList-content-view"><input type="checkbox" name="chkall" value="0" <? if($isexits) echo "onClick=\"docheck(this.form,0);\""?>></td>
			<td width="20%" class="newsList-content-title">Tiêu đề </td>

	        <td width="29%" class="newsList-content-title">Topic Quảng cáo </td>
          <td width="17%" class="newsList-content-view"><div align="center">Ngày Tháng </div></td>
		  <td width="8%" class="newsList-content-view"><div align="center">Hiển thị </div></td>
		  <td width="9%" class="newsList-content-view"><div align="center">Thứ tự </div></td>
		  <td width="14%" class="newsList-content-view"><div align="center">Tùy chọn </div></td>
		</tr>
				<?
				while($row = mysql_fetch_array($rss))
				{
					$i++;
					$qc_id = $row[qc_id];
					$qc_tieude = $row[qc_tieude];
					$qc_src = "../upload/".$row[qc_src];
					$qc_width = $row[qc_width];
					$qc_height = $row[qc_height];
					$qc_kieu_src = $row[qc_kieu_src];
					$qc_vitri = $row[qc_vitri];
					$qc_ngaythang = format_date($row[qc_ngaythang]);
					$qc_hienthi = $row[qc_hienthi];
					
				?>				
		<tr onmouseover="this.bgColor='#FEF2CB';" onmouseout="this.bgColor='#FFFFFF';" class="newsList-content-list" <? if($i%2==0) echo "bgcolor='#f2fff2'";?>>
			<td class="newsList-content-title"><input type="checkbox" name="Xoa" value="<?=$rvc_id?>" onClick="docheckone(this.form);"></td>
			<td class="newsList-content-title">
            	<table cellpadding="0" cellspacing="0" width="100%">
                <tr>
					<td>
						<a class="newsList-link newsList-name" href="">
						<b><?=$qc_tieude?></b></a>					</td>
                 </table>			</td>
			<td class="newsList-content-title" align="center">
				<?
					if($row[qc_kieu_src] == 0){
						echo "<a target=\"_blank\" href=\"".$qc_lienket."\">" . DisplayImage($qc_src,200,100,0," title = '".$qc_tieude."'") . "</a>";
					}else{
						echo flash($qc_src,$qc_lienket,200,100);
					}
				?>
			</td>
			<td class="newsList-content-view">
				<div align="center">
			  <?=$qc_ngaythang?>
			  </div></td>
			<td class="newsList-content-view"><div align="center"><a href="?mod=adv&method=act&act=<?=$qc_hienthi;?>&id=<?=$qc_id?>&HT=<?=$HT?>"><?=ImgActive($qc_hienthi);?></a></div></td>
			<td class="newsList-content-view"><div align="center"> <a href="?mod=adv&amp;method=move&amp;move=1&amp;id=<?=$qc_id?>&HT=<?=$HT?>" class="menu"><img src="images/down.gif" border="0" /></a> <a href="?mod=adv&amp;method=move&amp;move=-1&amp;id=<?=$qc_id?>&HT=<?=$HT?>" class="menu"><img src="images/up.gif" border="0" /></a> </div></td>
		  <td class="newsList-content-view"><div align="center">
		  <a href="?mod=adv.add&method=edit&id=<?=$qc_id?>" class="menu"><img src="images/edit.gif" border="0" /></a> <a href="?mod=adv&amp;method=delete&amp;id=<?=$qc_id?>&KCL=<?=$KCL?>&CL=<?=$CL?>&HT=<?=$HT?>&VT=<?=$VT?>" class="menu" onclick="return confirm('Bạn có chắc chắn muốn xóa không?')"><img src="images/delete_on.gif" border="0" /></a></div></td>
        </tr>
		<? }?>
	<tr>
   <td colspan="11" align="center">
   <input type="submit" name="submit" value="   Xoá   " class="Button">
   <input type="reset" value="Làm lại" class="Button">   </td>
   </tr>
</table>
	</form>
	<div class="newsList-pagging">
	<div class="raovat-paging-bound">
	<span style="padding:5px;">
	<p align="center" class="font">
			<?php echo page_div( "?mod=adv&HT=$HT&p=%d_pg", "10", ceil ( $numofpages ), $page ); ?>
	</p>
	</span>
	</div>
	</div>
	<div class="newsList-button-back"><a href="javascript: history.back()">[Quay lại]</a></div>